<?php

namespace App\Http\Controllers\Admin;

use App\Handlers\ImageUploadHandler;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function __construct()
    {
        $this->middleware(['admin.auth', 'admin.owns']);
    }

    /**
     * 上传文件
     *
     * @param Request $request
     * @return array
     */
    protected function upload($file)
    {
        $uploadHandler = new ImageUploadHandler();
        $path = $uploadHandler->save($file, 'news');
        return [
            'errno' => 0,
            'data' => [$path['path']]
        ];
    }
}
